import Vue from 'vue'
import Vuex from 'vuex'
import Storage from '@/utils/storageUtils'

Vue.use(Vuex)

const store = new Vuex.Store({
  state: {
    token: Storage.Local.get("token") ? Storage.Local.get("token") : null,
    userInfo: Storage.Local.get("userInfo") ? Storage.Local.get("userInfo") : null,
    category: Storage.Session.get("category") ? Storage.Session.get("category") : null
  },
  getters: {
    getCategory(state) {
      return state.category;
    },
    getToken(state) {
      return state.token;
    },
    getUserInfo(state) {
      return state.userInfo;
    }
  },
  mutations: {
    setCategory(state, val) {
      state.category = val;
      Storage.Session.set("category", val);
    },
    setToken(state, val) {
      state.token = val;
      Storage.Local.set("token", val);
    },
    setUserInfo(state, val) {
      state.userInfo = val;
      Storage.Local.set("userInfo", val);
    }
  }
});

export default store;
